livecodefandomcom-20200223-history
Split
Transforms a list into an array. Syntax: split {by | using | with} {row | column} Examples: put "one,two,three" into tData split tData by comma // RESULT // tData1 = "one" // tData2 = "two" // tData3 = "three" put "one;;two;;three" into line 1 of tData put "ben;;fraser;;elanor" into line 2 of tData put "apple;;orange;;grape" into line 3 of tData set the columndel to ";;" split tData by column // RESULT // tData1 = // one // two // three // tData2 = // ben // fraser // elanor // tData3 = // apple // orange // grape From LiveCode 7.0, you can pass a string of characters as a column and row delimiter (it is no longer restricted to a single character). From LiveCode 8.0, you can split by empty delimiters, which are treated as never appearing in the input string. Use the split command to place a list in an array so you can easily address each part of the list. The split command separates the parts of the variable into elements of an array. After the command is finished executing, the variable specified is an array. If you don't specify a secondaryDelimiter, then a simple numeric array is created, with each key being a number, starting with 1. If you specify a secondaryDelimiter, the key for each element is the first portion of each part of the variable, separated from the element's content by the secondaryDelimiter. For example, if the primaryDelimiter is return and the secondaryDelimiter is space, the remainder of each line of the variable is placed in an array element whose key is the first word of the line. If you use the as set form the split command converts the passed variable to an array with the keys being equal to the original list and the values being true. For example, the following statements create an array: put "A apple;;B bottle;;C cradle" into myVariable split myVariable by ";;" and space # myVariable"A" = apple # myVariable"B" = bottle # myVariable"C" = cradle Using the split command can discard data if any of the keys in the original variable are duplicated. If more than one part of the variable delimited by the primaryDelimiter has the same first portion delimited by the secondaryDelimiter, only the element corresponding to the first part is created. (For example, if you are splitting a variable by return and space, and two lines happen to have the same first word, only one of the lines is retained in the array.) Only one element is created for each unique key. Splitting a string by row converts the string into an array where each element of the array corresponds to a row in the string separated by the rowDelimiter. Splitting a string by column converts the string into an array where each element of the array corresponds to a column in the string separated by the columnDelimiter. Parameters: *variable: Any variable that is not an array *primaryDelimiter: A string of characters or an expression that evaluates to astring of characters. *secondaryDelimiter: A string of characters or an expression that evaluates to astring of characters. *The result: If the first form of the split command is used, the parts that becomeelements are defined by the primaryDelimiter. For example, if the primaryDelimiter is return, each line of the variable becomes an element in the resulting array.The resulting array looks like this:. If the second form of the split command is used, the string is split into elements of an array where each element using the rowDelimiter orcolumnDelimiter, where each element of the resulting array is a row orcolumn of the string respectively. See also: Combine, return (constant),extents (function),keys (function),columnDelimiter (property),rowDelimiter (property), Category: properties Category:Array